using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.Faces.Base;
using Habanero.Faces.Win;

namespace FireStarterModeller.UI
{
    public class ProjectAssemblyInfoControl : UserControlWin, IBOEditorControl
    {
        private IPanelInfo _panelInfo;
        private readonly IControlFactory _controlFactory;

        public ProjectAssemblyInfoControl(IControlFactory controlFactory)
        {
            _controlFactory = controlFactory;
            InitialiseControl();
        }

        private void InitialiseControl()
        {
            PanelBuilder panelBuilder = new PanelBuilder(_controlFactory);
            _panelInfo = panelBuilder.BuildPanelForForm(ClassDef.Get<DMAssembly>().UIDefCol["default"].UIForm);
            BorderLayoutManager layoutManager = _controlFactory.CreateBorderLayoutManager(this);
            layoutManager.AddControl(_panelInfo.Panel, BorderLayoutManager.Position.Centre);
        }

        public IPanelInfo BusObjectPanelBuilderInfo
        {
            get { return _panelInfo; }
        }

        public IBusinessObject BusinessObject
        {
            get { return _panelInfo.BusinessObject; }
            set { _panelInfo.BusinessObject = value; }
        }

        public void DisplayErrors()
        {
            
            BusObjectPanelBuilderInfo.ApplyChangesToBusinessObject();
        }

        public void ClearErrors()
        {
            BusObjectPanelBuilderInfo.ClearErrorProviders();
        }

        #region Implementation of IBOEditorControl

        /// <summary>
        ///             Applies any changes that have occured in any of the Controls on this control's to their related
        ///             Properties on the Business Object.
        /// </summary>
        public void ApplyChangesToBusinessObject()
        {
            this._panelInfo.ApplyChangesToBusinessObject();
        }

        /// <summary>
        ///             Does the business object controlled by this control or any of its Aggregate or Composite children have and Errors.
        /// </summary>
        public bool HasErrors
        {
            get { throw new System.NotImplementedException(); }
        }

        /// <summary>
        ///             Does the Business Object controlled by this control or any of its Aggregate or Composite children have and warnings.
        /// </summary>
        public bool HasWarning
        {
            get { throw new System.NotImplementedException(); }
        }

        /// <summary>
        ///              Returns a list of all warnings for the business object controlled by this control or any of its children.
        /// </summary>
        public ErrorList Errors
        {
            get { throw new System.NotImplementedException(); }
        }

        /// <summary>
        ///             Does the business object being managed by this control have any edits that have not been persisted.
        /// </summary>
        /// <returns>
        /// </returns>
        public bool IsDirty
        {
            get { throw new System.NotImplementedException(); }
        }

        /// <summary>
        ///             Returns a list of all warnings for the business object controlled by this control or any of its children.
        /// </summary>
        /// <returns>
        /// </returns>
        public ErrorList Warnings
        {
            get { throw new System.NotImplementedException(); }
        }

        #endregion
    }
}